import {createRouter, createWebHistory} from 'vue-router';

import AdminLayout from '@/pages/admin/layout/index.vue';
import FrontendLayout from '@/pages/frontend/layout/index.vue';

// 静态路由
const routes = [
    {
        path: '/',
        redirect: '/index'
    },
    {
        path: '/index',
        name: 'index',
        component: FrontendLayout,
        redirect: '/home',
        meta: {
            isPublic: true
        },
        children: [
            {
                path: '/home',
                name: 'home',
                meta: {
                    isPublic: true
                },
                component: () => import('@/pages/frontend/blog/index.vue'),
            },
            {
                path: '/article/read/:id',
                name: 'read-article',
                meta: {
                    isPublic: true
                },
                component: () => import('@/pages/frontend/blog/readArticle.vue'),
            },
            {
                path: '/archive',
                name: 'archive',
                meta: {
                    isPublic: true
                },
                component: () => import('@/pages/frontend/archive/index.vue'),
            },
        ]
    },
    {
        path: '/admin',
        // redirect: '/admin/dashboard',
        name: 'admin',
        component: AdminLayout,
        children: [
            {
                path: 'dashboard',
                name: 'dashboard',
                component: () => import('@/pages/admin/dashboard/index.vue'),
            },
            {
                path: 'article',
                name: 'article',
                redirect: '/admin/article/list',
                component: () => import('@/pages/admin/article/index.vue'),
                children: [
                    {
                        path: 'list',
                        name: 'article-list',
                        component: () => import('@/pages/admin/article/list.vue'),
                    },
                    {
                        path: 'write',
                        name: 'article-write',
                        component: () => import('@/pages/admin/article/write.vue'),
                    },
                ]
            },
            {
                path: 'category',
                name: 'category',
                component: () => import('@/pages/admin/category/index.vue'),
            },
            {
                path: 'tags',
                name: 'tags',
                component: () => import('@/pages/admin/tags/index.vue'),
            },
            {
                path: 'comment',
                name: 'comment',
                component: () => import('@/pages/admin/comment/index.vue'),
            },
        ]
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/pages/login/index.vue')
    },
    {
        path: '/:pathMatch(.*)*',
        component: () => import('@/pages/error/404.vue')
    }
];

const router = createRouter({
    history: createWebHistory(),
    routes,
});

export default router;